<?php

class Light_View_Helper_Translate extends Light_View_Helper_Abstract
{
    /**
	 * (non-PHPdoc)
	 * @see Light_View_Helper_Abstract::__construct()
	 */
    public function __construct()
    {
        parent::__construct();

        Light_Core::loadTranslations();
    }

    /**
     * @param string $key
     * @param string $code
     * @return string
     */
    public function translate($key, $code = null)
    {
        if (LIGHT_LANGUAGE_ENABLE && $code === null) {
            $r = $this->view->getController()->getRequest();
            $code = $r->getParam('lang', LIGHT_LANGUAGE_DEFAULT);
        } else {
            $code = LIGHT_LANGUAGE_DEFAULT;
        }

        if (isset(Light_Core::$translations[$code][$key])) {
            return Light_Core::$translations[$code][$key];
        }

        return $key;
    }
}